//
//  MyCenterController.m
//  LearnObjectiveC
//
//  Created by 吴可高 on 16/5/5.
//  Copyright © 2016年 吴可高. All rights reserved.
#import "MyCenterController.h"
#import "TestingViewController.h"
#import "HomePageContentView.h"
#import "MyStatisticGraphicView.h"
#import "AccountRequestTool.h"
#import "ColumeBarController.h"
#import "MansoryScrollViewAutoViewController.h"
#import "AutoScrollConflictViewController.h"

#import "BrokenLine.h"
#import "BrokenPointValue.h"
#import "SNChart.h"


@interface UsingMasonry : UIView

@end
@implementation UsingMasonry

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self setUp];
    }
    return self;
}
-(void)setUp
{
    self.backgroundColor = KColor(247, 247, 247);
    UIView * headView = [UIView new];
    headView.backgroundColor  = [UIColor blueColor];
    headView.layer.masksToBounds = YES;
    headView.layer.cornerRadius  =5.f;
    [self addSubview:headView];
    [headView mas_makeConstraints:^(MASConstraintMaker *make) {
        UIEdgeInsets insets = UIEdgeInsetsMake(10, 10,kScreen_Height*2/3.f,kScreen_Width*2/3.f);
        make.top.left.right.and.bottom.mas_equalTo(self).with.insets(insets);
    }];
    //
    UIView * centerView = [UIView new];
    centerView.backgroundColor = [UIColor grayColor];
    centerView.layer.masksToBounds = YES;
    centerView.layer.cornerRadius = 2.f;
    [self addSubview:centerView];
    
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_top).with.offset(20);
        make.left.mas_equalTo(self.mas_left).with.offset(20);
        make.center.mas_equalTo(self);
        
    }];
}
@end

@interface MyCenterController ()
@property (strong, nonatomic) MyStatisticGraphicView * staticGrphicView;
@property (strong, nonatomic) BrokenLine * brokenLine;
@property (strong, nonatomic) NSArray <BrokenPointValue*>* items;
@property (strong, nonatomic) ColumeBarController * columnBarController;
@property (strong, nonatomic) UsingMasonry * usingMasonary;
@property (strong, nonatomic) MansoryScrollViewAutoViewController * masonaryScrollViewController;

@property (strong, nonatomic) AutoScrollConflictViewController * autoScrollViewConfilctController;

@end
@implementation MyCenterController

-(void)viewDidLoad
{
    [super viewDidLoad];
     self.view.backgroundColor  = [UIColor whiteColor];
    [self  setSubObjectView];
    [self initWithSubView];
    [self initData];
    [self.view addSubview:self.brokenLine];
//    [self downloadInfoAsynRequest];
    [self initLineChartView];
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

#pragma mark ViewController AsynRequestData
-(void)downloadInfoAsynRequest;
{
    [AccountRequestTool downloadSessTaskPath:@"/upload/201604071809088861.mp3" savePath:@"gmail" success:^(NSString *meg, id responseObject) {
        
        NSData * downData = [NSData dataWithContentsOfFile:responseObject options:NSDataReadingMappedIfSafe error:nil];
        NSLog(@"down load data.length = %@",downData);
        
    } failure:^(NSError *error) {
        
    } progress:^(int64_t progress) {
        
    }];
}

#pragma mark ViewController Algorithm Processor
-(void)initData
{
    BrokenPointValue * value0 = [BrokenPointValue setPointx:10 pointy:10 vlalues:@"(10-10)" color:nil];
    BrokenPointValue * value1 = [BrokenPointValue setPointx:30 pointy:30 vlalues:@"(30-30)" color:nil];
    BrokenPointValue * value2 = [BrokenPointValue setPointx:40 pointy:80 vlalues:@"(40-80)" color:nil];
    
    BrokenPointValue * value3 = [BrokenPointValue setPointx:90 pointy:100 vlalues:@"(90-100)" color:nil];
    BrokenPointValue * value4 = [BrokenPointValue setPointx:100 pointy:46 vlalues:@"(100-46)" color:nil];
    BrokenPointValue * value5 = [BrokenPointValue setPointx:130 pointy:76 vlalues:@"(130-76)" color:nil];
    _items = @[value0,value1,value2,value3,value4,value5];

}
#pragma mark ViewController Initialize SubObjectView
-(void)setSubObjectView
{
    [self.view addSubview:self.usingMasonary];
    [self.usingMasonary mas_makeConstraints:^(MASConstraintMaker *make) {
        UIEdgeInsets edgeInset = UIEdgeInsetsMake(kNavigationBarHeight + 10, 10, 10 + 48, 10);
        make.edges.mas_equalTo(self.view).insets(edgeInset);
        }];
}

- (void)initWithSubView
{
    [self customNavigationBarStyleWithleftBarItems:@[@"",@""]
                               navigationItemTitle:@"centerVC"
                            andRightBarButtonItems:@[@"",@""]
                         leftBarItemHandleComplete:^(NSInteger idx, UIButton *parameter)
     {
         
     }
                        rightBarItemHanbleComplete:^(NSInteger idx, UIButton *parameter)
     {
     }];
    [self setNavigationItemTitle:@"centerVC"];
}

-(void)initLineChartView
{
    SNChart * chart = [[SNChart alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height - 100) withDataSource:self andChatStyle:SNChartStyleLine];
     chart.curve = YES;
    [chart showInView:self.view];
}

#pragma mark --viewController getter methods
- (BrokenLine *)brokenLine
{
    _brokenLine = ({
        if (!_brokenLine) {
            _brokenLine = [[BrokenLine alloc]initWithFrame:CGRectMake(0, kNavigationBarHeight, kScreen_Width, kScreen_Height - kNavigationBarHeight) withData:_items];
            _brokenLine.backgroundColor = [UIColor whiteColor];
        }
        _brokenLine.animated = YES;
        _brokenLine.timeInterval = 2.f;
        _brokenLine;
    });
    return _brokenLine;
}

-(UsingMasonry *)usingMasonary
{
    _usingMasonary = ({
        if (!_usingMasonary) {
            _usingMasonary = [[UsingMasonry alloc]initWithFrame:CGRectZero];
        }
        _usingMasonary;
    });
    return _usingMasonary;
}

-(ColumeBarController *)columnBarController
{
    _columnBarController = ({
        if (!_columnBarController) {
            _columnBarController  = [[ColumeBarController alloc]init];
        }
        _columnBarController;
    });
    return _columnBarController;
}
-(MansoryScrollViewAutoViewController *)masonaryScrollViewController
{
    _masonaryScrollViewController = ({
        if (!_masonaryScrollViewController) {
            _masonaryScrollViewController =  [[MansoryScrollViewAutoViewController alloc]init];
        }
        _masonaryScrollViewController;
    });
    return _masonaryScrollViewController;
}
-(AutoScrollConflictViewController *)autoScrollViewConfilctController
{
    _autoScrollViewConfilctController = ({
        if (!_autoScrollViewConfilctController) {
            _autoScrollViewConfilctController = [[AutoScrollConflictViewController alloc]init];
        }
        _autoScrollViewConfilctController;
    });
    return _autoScrollViewConfilctController;
}
#pragma mark Possess  Delegate ViewController（委托代理者）
- (NSArray *)chatConfigYValue:(SNChart *)chart {
    return @[@"0.1",@"0.5",@"0.70",@"0.30",@"0.50",@"0.014",@"0",@"0.14"];
}

- (NSArray *)chatConfigXValue:(SNChart *)chart {
    return @[@"12-1",@"12-2",@"12-3",@"12-4",@"12-5",@"12-6",@"12-7",@"12-8",@"12-9",@"12-10"];
}


#pragma mark IBOutlet Action ViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.navigationController pushViewController:self.autoScrollViewConfilctController animated:YES];
}
#pragma mark Other Method
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
     self.staticGrphicView.frame = CGRectMake(0, kNavigationBarHeight, kScreen_Width, kScreen_Height - kNavigationBarHeight);
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
}
@end
